package common.store.web.controller;

import common.store.web.service.UserService;
import common.store.web.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/checkUser")
public class CheckUserServelt extends HttpServlet {
    UserService userService;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        userService =new UserServiceImpl();
        String username = req.getParameter("username");
        Integer count = userService.getUsername(username);
        resp.setContentType("text/html;charset=utf-8");
        if(count > 0){
            resp.getWriter().write("该用户名已存在！");
        }else{
            resp.getWriter().write("用户名可用！");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
